﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebTest.aspx.cs" Inherits="Web4Comment.WebTest" %>
<%@ Register assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI.DataVisualization.Charting" tagprefix="asp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title> Nonove js timer 计时器 </title>
    <!--<script type="text/javascript" src="js/clock.js"></script>-->
    <script type="text/javascript">
        
        var se, m = 0, h = 0, s = 0, ss = 0, isStart = true;
        function second() {
            if (ss > 0 && (ss % 100 == 0)) { s += 1; ss = 1; }
            if (s > 0 && (s % 60) == 0) { m += 1; s = 0; }
            if (m > 0 && (m % 60) == 0) { h += 1; m = 0; }
            t = h + "时" + m + "分" + s + "秒" + ss + "毫秒";
            document.getElementById("showtime").innerHTML = t;
            ss += 1;
        }
        function startclock() {
            if (se == null || se == 'undefined' || istrue)
                se = setInterval("second()", 1);
            istrue = false;
        }
        function pauseclock() { clearInterval(se); istrue = true; }
        function stopclock() { clearInterval(se); m = h = s = 0; istrue = true; }


        function myClose() { document.getElementById('Button1').click(); alert(t) };


        var xmlHttp;
        function showCustomer() {
            alert("start");
            xmlHttp = GetXmlHttpObject();
            if (xmlHttp == null) {
                alert("您的浏览器不支持AJAX！");
                return;
            }

            var d1 = new Date();
            var t = d1.getFullYear() + ":" + d1.getMonth() + ":"
            + d1.getDate() + ":" + d1.getHours() + ":" + d1.getMinutes() + ":" + d1.getSeconds() + ":" + d1.getMilliseconds()+":"+<%=x %>;

            var url = "WebTest_ajax.aspx?t=" + t; //传到服务端上
            xmlHttp.onreadystatechange = stateChanged;
            xmlHttp.open("GET", url, true);
            xmlHttp.send(null);
        }
        function stateChanged() {
            document.getElementById("sessiontext").innerHTML = xmlHttp.responseText;
        }
        function GetXmlHttpObject() {
            var xmlHttp = null;
            try {
                // Firefox, Opera 8.0+, Safari
                xmlHttp = new XMLHttpRequest();
            }
            catch (e) {
                // Internet Explorer
                try {
                    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e) {
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
            }
            return xmlHttp;
        }

        function start() {
            var d1 = new Date();
            document.getElementById("date1").value = d1.getFullYear() + ":" + d1.getMonth() + ":"
            + d1.getDate() + ":" + d1.getHours() + ":" + d1.getMinutes() + ":" + d1.getSeconds() + ":" + d1.getMilliseconds()+":"+<%=x %>;
            document.getElementById('Button1').click()
        }

        function end() {
            document.getElementById("date2").value = new Date();
            document.getElementById('Button3').click()
            alert(document.getElementById("date2").value);
        }

        function xx()
        {
        document.getElementById('Button3').click();
        }
        //window.onload = function (){start();}
        //window.onload = function () { startclock(); }
        window.onload = function(){alert("start");startclock()}
        window.onbeforeunload  = function(){document.getElementById('Button3').click()}
    </script>

</head>
<body onblur="document.getElementById('Button3').click()" onfocus="startclock()">
    <form id="form1" runat="server">
       <h1 id="showtime" style="color:#ff0000;font-size:124px;">0时0分0秒</h1><br/>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    <asp:Button ID="Button1" runat="server" style="display:none" onclick="Button1_Click1"/>
    <asp:Button ID="Button3" runat="server" Text="end" onclick="Button3_Click" />
    &nbsp;<asp:Button ID="Button4" runat="server" Text="calculateTime" 
           onclick="Button4_Click" />
    <span id="sessiontext" style="color: #FF0000;font-size:124px;">
    </span>
    <br />
       <asp:Chart ID="FriendChat" runat="server" DataSourceID="DS" RightToLeft="Yes">
           <Series>
               <asp:Series Name="Series1" XValueMember="username" 
                   YValueMembers="secondsInterval" ChartType="Bar">
               </asp:Series>
           </Series>
           <ChartAreas>
               <asp:ChartArea Name="ChartArea1">
               </asp:ChartArea>
           </ChartAreas>
       </asp:Chart>
       <asp:SqlDataSource ID="DS" runat="server" 
           ConnectionString="<%$ ConnectionStrings:UnlessCommentConnectionString %>" 
           SelectCommand="select username,secondsInterval from((select top 5 userid, sum(x) as secondsInterval from
(SELECT userid, DATEDIFF(SECOND,start_time,end_time) as x
FROM [UnlessComment].[dbo].[Time])A 
group by userid order by secondsInterval)B left join [UnlessComment].[dbo].[User]C on B.userid = C.id)">
       </asp:SqlDataSource>
    </form>
    <br />
    

</body>
</html>
